//
//  OKDoctorRegisterCell.m
//  ZLFastDoctor
//
//  Created by answer on 16/5/25.
//  Copyright © 2016年 LS. All rights reserved.
//

#import "OKDoctorRegisterCell.h"
#import <Masonry/Masonry.h>

@interface OKDoctorRegisterCell ()
@property (strong, nonatomic) UILabel *label;
@end

@implementation OKDoctorRegisterCell

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

- (void)setIndexpath:(NSIndexPath *)indexpath {
    _indexpath = indexpath;
    
    
    
    if (indexpath.section == 0 && indexpath.item != 0) {
        
        NSDateComponents * components = [[NSDateComponents alloc] init];
        
        components.day = indexpath.item-1;
        NSCalendar * calendar = [NSCalendar currentCalendar];
        
        NSDate * currentDate = [NSDate date];
        NSDate * nextData = [calendar dateByAddingComponents:components toDate:currentDate options:NSCalendarMatchStrictly];
        
        NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
        
        formatter.dateFormat = @"MM月dd";
        NSString * str = [formatter stringFromDate:nextData];
        //NSLog(@"%@",str);
        
        // 获取星期几
        //NSCalendar *calendar = [NSCalendar currentCalendar];
        //作用分开获得 时分秒
        NSDateComponents *component = [calendar components:NSCalendarUnitWeekday fromDate:nextData];
       // NSDateComponents *component = [calendar components:NSCalendarUnitHour | NSCalendarUnitMinute fromDate:nextData];
        
        //NSLog(@"%zd", component.weekday);
        
        switch (component.weekday) {
            case 1:
                self.label.text = [NSString stringWithFormat:@"周日\n%@", str];
                break;
            case 2:
                self.label.text = [NSString stringWithFormat:@"周一\n%@", str];
                break;
            case 3:
                self.label.text = [NSString stringWithFormat:@"周二\n%@", str];
                break;
            case 4:
                self.label.text = [NSString stringWithFormat:@"周三\n%@", str];
                break;
            case 5:
                self.label.text = [NSString stringWithFormat:@"周四\n%@", str];
                break;
            case 6:
                self.label.text = [NSString stringWithFormat:@"周五\n%@", str];
                break;
            case 7:
                self.label.text = [NSString stringWithFormat:@"周六\n%@", str];
                break;
                
                
            default:
                break;
        }
        

        self.label.font = [UIFont systemFontOfSize:12];

    }

    
    if (indexpath.section == 1 && indexpath.item == 5) {
        self.label.text = @"有号";
    }
    
    if (indexpath.section == 2 && indexpath.item == 2) {
        self.label.text = @"有号";
    }
    
    if (indexpath.section == 3 && indexpath.item == 4) {
        self.label.text = @"有号";
    }
    
    

    
    if (indexpath.item == 0) {
        switch (indexpath.section) {
            case 1:
                self.label.text = @"上午";
                break;
            case 2:
                self.label.text = @"中午";
                break;
            case 3:
                self.label.text = @"下午";
                break;
                
            default:
                break;
        }
    }
}

- (void)setupUI {
    
    [self.contentView addSubview:self.label];
    [self.label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
}

- (UILabel *)label {
    if (_label == nil) {
        _label = [[UILabel alloc] init];
        _label.textAlignment = NSTextAlignmentCenter;
        _label.numberOfLines = 0;
        _label.font = [UIFont systemFontOfSize:12];
        _label.layer.borderWidth = 1;
        _label.layer.borderColor = [UIColor lightGrayColor].CGColor;
    }
    return _label;
}

@end






